//
//  LabelAndCollectionViewReusableView.m
//  14_半糖_老师讲的
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LabelAndCollectionViewReusableView.h"
#define kCollectionViewReuse @"reuseSmall"
@interface LabelAndCollectionViewReusableView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation LabelAndCollectionViewReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        CGFloat height = (CGRectGetHeight(frame) - 50 - 40) / 3;
        flowLayout.itemSize = CGSizeMake((CGRectGetWidth(frame) - 30) / 2, height);
        // 算出来之后设成0
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.minimumLineSpacing = 15;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, frame.size.width, frame.size.height - 50) collectionViewLayout:flowLayout];
        _collectionView.pagingEnabled = YES;
        [self addSubview:_collectionView];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 12;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (indexPath.item == 8) {
        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    }
    cell.backgroundColor = [UIColor blueColor];
    return cell;
}


@end
